﻿using System;
using System.Collections.Generic;
using SystemX;
using SystemX.Infrastructure;

namespace SystemX.Web.Infrastructure
{
    [Serializable]
    public partial class ResponseBase
    {
		public ResponseBase() {
			Extra = new Dictionary<string, object>();
		}
        public virtual bool IsOk { get; set; }
        public virtual string Title { get; set; }
        public virtual string Flag {
            get
            {
                return IsOk?"alert_ok":"alert_error";
            }
        }
        public virtual string Body { get; set; }
        public bool IsLogined {
            get
            {
                return Utils.IsLogined;
            }
        }
		public Dictionary<string, object> Extra{ get; set; }
		/// <summary>
		/// Fill data with a bll message
		/// </summary>
		/// <param name="msg"></param>
		/// <returns></returns>
		public virtual void Load(BOMessager msg) {
			IsOk = !msg.IsError;
			Title = IsOk ? "" : msg.Body;
			Body = IsOk ? msg.Body : "";
			Extra = msg.Context;
		}
    }
	[Serializable]
	public partial class ResponseBase<T> : ResponseBase 
	where T:ResponseBase<T>
	{
		new public virtual T Load(BOMessager msg) {
			base.Load(msg);
			T X = (T)this;
			return X;
		}
	}
}
